/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.umlv2.alvin.ui.dialog;

import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.SwingUtilities;
import org.umlv2.alvin.bean.ProjectBean;

/**
 *
 * @author Administrator
 */
public class NewFileDialog extends BaseDialog {

    /**
     * Creates new form NewFileDialog
     */
    public NewFileDialog() {
        setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        initComponents();

        jList1.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        jList1.setFixedCellWidth(80);
        jList1.setFixedCellHeight(80);
        jList1.setVisibleRowCount(0);
        jList1.setListData(createDefaultData());
        setLocationRelativeTo(null);
        getRootPane().setDefaultButton(jButton1);

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                jList1.setSelectedIndex(0);
            }
        });
        jLabel1.setVisible(false);
        jTextField1.setVisible(false);

    }

    private ProjectBean[] createDefaultData() {
        ProjectBean[] data = new ProjectBean[3];
        ProjectBean activeProject = new ProjectBean();
        activeProject.setName("活动图");
        activeProject.setPath("");
        activeProject.setSaved(true);
        activeProject.setType("0");
        data[0] = activeProject;
        ProjectBean usercaseProject = new ProjectBean();
        usercaseProject.setName("用例图");
        usercaseProject.setPath("");
        usercaseProject.setSaved(true);
        usercaseProject.setType("1");
        data[1] = usercaseProject;
        ProjectBean serialProject = new ProjectBean();
        serialProject.setName("时序图");
        serialProject.setPath("");
        serialProject.setSaved(true);
        serialProject.setType("2");
        data[2] = serialProject;
        return data;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jButton1.setText("确 定");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("取 消");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setText("项目名称：");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 54, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ProjectBean bean = (ProjectBean) jList1.getSelectedValue();
        if (bean == null) {
            return;
        }
        setDialog_status(STATUS_OK);
        setVisible(false);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        setDialog_status(STATUS_CANCEL);
        setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    public ProjectBean getProjectBean() {
        ProjectBean bean = (ProjectBean) jList1.getSelectedValue();
        bean.setName(jTextField1.getText());
        return bean;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
